using System;
using System.Net.Sockets;
using System.IO;
public class Client {
	static public void Main3(string[] Args) {
		TcpClient socketForServer;
		try {
			socketForServer = new TcpClient("127.0.0.1", 8180);
		} catch {
			Console.WriteLine(
			"Failed to connect to server at {0}:999", "localhost");
			return;
		}
		NetworkStream networkStream = socketForServer.GetStream();
		StreamReader streamReader = new StreamReader(networkStream);
		StreamWriter streamWriter = new StreamWriter(networkStream);
			try {
				while (true) {
					string outputString;
					// read the data from the host and display it
					{
						Console.WriteLine("Client wait for message");
						outputString = streamReader.ReadLine();
						Console.WriteLine(outputString);
						Console.WriteLine("Write client message");
						streamWriter.WriteLine(Console.ReadLine());
						streamWriter.Flush();
					}
				}
			} catch {
				Console.WriteLine("Exception reading from Server");
			}
		
		// tidy up
		networkStream.Close();
	}
}
